package org.mobai.service;

import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.mobai.mapper.PersonDao;
import org.mobai.mapper.StudentDao;
import org.mobai.model.Order;
import org.mobai.mapper.OrderDao;
import org.mobai.model.Person;
import org.mobai.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 * @version v1.0
 * @className OrderService
 * @description
 * @date 2024/5/9 星期四 15:21
 **/
@Service
public class OrderService{

    @Autowired
    OrderDao orderDao;

    @Autowired
    StudentDao studentDao;

    @Autowired
    PersonDao personDao;

    public void testInsertOrder() {

        for (int i = 0; i < 10; i++) {
//            orderDao.insertOrder(100 + i, "大冰箱" + i);

            Order order = new Order();
            order.setUserId(100+i);
            order.setProductName("大冰箱"+i);
            orderDao.insert(order);
        }

    }

    public void queryById(){
        Order order = orderDao.selectById(1);
        System.out.println(order);


        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        wrapper.between("order_id", 0, 110);

        List<Order> orders = orderDao.selectList(wrapper);
        System.out.println(orders);
    }


    public void insertStudent(){
        Student student = new Student();
        student.setName("臧三");
        studentDao.insert(student);

        Student student1 = studentDao.selectById(1);
        System.out.println(student1);
    }


    public void insertPerson(){
        Person person = new Person();


        person.setAge(RandomUtil.randomInt(0,1000));
        person.setName("zs"+person.getAge());

        personDao.insert(person);
    }
}